//
//  LDCollectionViewCell.m
//  Gift
//
//  Created by 李迪 on 15/11/7.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "LDCollectionViewCell.h"
#import "BaseHeader.h"

@interface LDCollectionViewCell ()

@property (nonatomic, retain)UIImageView *image;
@property (nonatomic, retain)UILabel *title;
@property (nonatomic, retain)UILabel *qian;
@property (nonatomic, retain)UILabel *like;



@end

@implementation LDCollectionViewCell

-(void)dealloc{
    
    [self.image release];
    [self.title release];
    [self.like release];
    [self.qian release];
    [super dealloc];
}


-(instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        
        [self createcollection];
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        NSString *passWord = [user objectForKey:@"night"];
        if ([passWord isEqualToString:@"yes"]) {
            
            [self.title setTextColor:[UIColor whiteColor]];
            [self.like  setTextColor:[UIColor whiteColor]];
            [self.qian  setTextColor:[UIColor whiteColor]];
        }
    }
    
    return self;
}



- (void)createcollection{
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, (SCREEN_WIDTH / 2) - 15, (SCREEN_HEIGHT / 3) + 20)];
    [self.contentView addSubview:view];
    
    self.image = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0,(SCREEN_WIDTH / 2) - 15, (SCREEN_HEIGHT / 3) - 55)];
    
    [view addSubview:self.image];

    
    self.title = [[UILabel alloc]initWithFrame:CGRectMake(5, (SCREEN_HEIGHT / 3) - 50, (SCREEN_WIDTH / 2) - 25, 40)];
    self.title.font = [UIFont systemFontOfSize:15];
    self.title.numberOfLines = 0;

    [view addSubview:self.title];
    
    UILabel *qianfuhao = [[UILabel alloc]initWithFrame:CGRectMake(5, (SCREEN_HEIGHT / 3) - 5, 15, 17)];
    qianfuhao.font = [UIFont systemFontOfSize:13];
    qianfuhao.text = @"￥";
    [view addSubview:qianfuhao];
    
    self.qian = [[UILabel alloc]initWithFrame:CGRectMake(20, (SCREEN_HEIGHT / 3) - 5, 60, 17)];
    self.qian.font = [UIFont systemFontOfSize:13];
    self.qian.textColor = [UIColor redColor];
    [view addSubview:self.qian];
    
    UIImageView *imagexin = [[UIImageView alloc]initWithFrame:CGRectMake(88, (SCREEN_HEIGHT / 3) - 3, 15, 15)];
    imagexin.image = [UIImage imageNamed:@"xin-3"];
    [view addSubview:imagexin];
    
    self.like = [[UILabel alloc]initWithFrame:CGRectMake(105, (SCREEN_HEIGHT / 3) - 5, 40, 17)];
    self.like.font = [UIFont systemFontOfSize:11];
    [view addSubview:self.like];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleChange:) name:@"lidi" object:nil];
    
    [self.image release];
    [self.title release];
    [self.like release];
    [self.qian release];
    [qianfuhao release];
    [imagexin release];
}

- (void)handleChange:(NSNotification *)Notification{
    
    NSString *passWord = [Notification object];
    if ([passWord isEqualToString:@"yes"]) {
        [self.title setTextColor:[UIColor whiteColor]];
        [self.like  setTextColor:[UIColor whiteColor]];
        [self.qian  setTextColor:[UIColor whiteColor]];
    }if ([passWord isEqualToString:@"no"]) {
        [self.title setTextColor:[UIColor blackColor]];
        [self.like  setTextColor:[UIColor blackColor]];
        [self.qian  setTextColor:[UIColor blackColor]];
    }

    
    
}

-(void)setModel:(SinglePieceModel *)model{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    [self.image sd_setImageWithURL:[NSURL URLWithString:model.cover_image_url]];
    self.title.text = model.name;
    self.like.text = model.favorites_count.stringValue;
    self.qian.text = model.price;
}






@end
